// https://www.luogu.com.cn/problem/P1803

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Compare {
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) const {
        return p1.second < p2.second;
    }
};

int main() {
    int n, a, b;
    scanf("%d", &n);
    vector<pair<int, int>> places;
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &a, &b);
        places.push_back(pair<int, int>(a, b));
    }

    sort(places.begin(), places.end(), Compare());
    int end = -1;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (places[i].first >= end) {
            end = places[i].second;
            cnt++;
        }
    }

    printf("%d\n", cnt);
    return 0;
}